package net.xju.mapper;


import net.xju.entity.Card;
import net.xju.entity.Clazz;
import net.xju.entity.Student;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public interface StudentMapper {
    // 查询
//    @Select("select * from newtable")
    List<Student> selectAll();
    // 添加
//    @Insert("insert into newtable(name,sn) values(#{name},#{sn})")
    Integer insert(Student student);

    Integer updateById(Student stu);
//    @Delete("delete from newtable where id =#{id}")
    Integer deleteById(int i);

    List<Student> selectBySn(String sn);

    Student selectBySnAndName(@Param("sn") String sn,@Param("name") String name);

    Student selectByMap(@Param("map") Map<String, Object> map);

    @MapKey("id")
    Map<String,Object> selectByMap1(String sn);

//    @Select("select * from newtable n join card c on n.card_id = c.id  where n.id =#{id}")
//    @Results({
//            @Result(property = "id", column = "id", id = true),
//            @Result(property = "sn", column = "sn"),
//            @Result(property = "name", column = "name"),
//            @Result(property = "cardId", column = "card_id"),
//            @Result(property = "clazzId", column = "clazz_id"),
//            @Result(property = "card.id",column = "id"),
//            @Result(property = "card.balance",column = "balance")
//    })
//    @Select("select * from javaee.newtable where id =#{id}")
//    @Results({
//            @Result(property = "id", column = "id", id = true),
//            @Result(property = "sn", column = "sn"),
//            @Result(property = "name", column = "name"),
//            @Result(property = "cardId", column = "card_id"),
//            @Result(property = "clazzId", column = "clazz_id"),
//            @Result(property = "card",
//                    column = "card_id",
//                    javaType = Card.class,
//                    one = @One(select = "net.xju.mapper.StudentMapper.selectByCardId")
//            ),
//    })
    Student selecetBySid(int id);

//    @Select("select * from javaee.card c  where id = #{cid}")
    Card selectByCardId(int cid);

//    @Select("select * from  javaee.clazz  where id = #{id}")
//    @Results({
//            @Result(property = "id",column = "id",id = true),
//            @Result(property = "clazzName",column = "clazz_name"),
//            @Result(property = "sum",column = "sum"),
//            @Result(property = "studentList",
//            column = "id",
//            javaType = List.class,
//            many = @Many(select = "net.xju.mapper.StudentMapper.selectByClazzId"))
//    })
    Clazz selectByCid(int id);

//    @Select("select * from javaee.newtable where clazz_id =#{id}")
    List<Student> selectByClazzId(int id);

    List<Student> selectByIds(@Param("ids") List<Integer> ids);

    Integer batchUpdate(ArrayList<Student> students);
}
